//
//  BDShopManagerTableViewCell.m
//  BadBoy
//
//  Created by wen on 2017/3/17.
//  Copyright © 2017年 com.8xiong. All rights reserved.
//

#import "BDShopManagerTableViewCell.h"

@interface BDShopManagerTableViewCell ()<UITextFieldDelegate>

@property (nonatomic, strong) UITextField *textField;
@property (nonatomic, copy) void(^strngChangeBlock)(NSString *changeString);

@end

@implementation BDShopManagerTableViewCell

- (void)configeWithModel:(id)model stringChangeBlock:(void(^)(NSString *changeString))strngChangeBlock{
    self.textLabel.text = model[@"title"];
    self.textField.text = model[@"subTitle"];
    self.textField.placeholder = model[@"placeHold"];

    if (model[@"canEdit"]) {
        self.textField.userInteractionEnabled = NO;
    }else{
        self.textField.userInteractionEnabled = YES;
    }
    
    self.strngChangeBlock = strngChangeBlock;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    self.textLabel.font = [UIFont systemFontOfSize:14];
    self.textLabel.textColor = [UIColor colorWithHexString:@"#4c4c4c"];
    [self.textLabel sizeToFit];
    self.textLabel.left = 10;
    self.textLabel.centerY = self.height / 2.0;
    
    self.textField.width = kBDScreenWidth - 10 - self.textLabel.right - 10;
    self.textField.right = self.width - 10;
    self.textField.height = self.height;
    self.textField.textColor = [UIColor colorWithHexString:@"#4c4c4c"];
    self.textField.tintColor = [UIColor colorWithHexString:@"#cccccc"];
    self.textField.font = [UIFont systemFontOfSize:13];
    [self.textField setValue:[UIColor colorWithHexString:@"#cccccc"] forKeyPath:@"_placeholderLabel.textColor"];
    [self.textField setValue:[UIFont systemFontOfSize:13] forKeyPath:@"_placeholderLabel.font"];
    self.textField.textAlignment = NSTextAlignmentRight;
}

- (void)textFieldDidEndEditing:(UITextField *)textField{
    if (self.strngChangeBlock) {
        self.strngChangeBlock(textField.text);
    }
}

- (UITextField *)textField{
    if (!_textField) {
        self.textField = [[UITextField alloc] init];
        _textField.delegate = self;
        [self.contentView addSubview:_textField];
    }
    return _textField;
}

@end
